import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import $style from './index.module.scss'
export default (props:{children:any; label?:any; labelWidth?:number|string; required?:boolean; border?:boolean}) => {
    let style = ''
    let labelWidth = props.labelWidth
    if(labelWidth) {
        if(typeof labelWidth == 'number') {
            labelWidth = Taro.pxTransform(labelWidth)
        }

        style += `width:${labelWidth}`
    }

    let clasName = $style.formItem
    if(props.border !== false) {
        clasName += ' ' + $style.border
    }

    return <View className={clasName}>
        <View style={style} className={$style.label}>
            {props.required &&
                <text className={$style.required}>*</text>
            }
            {props.label}
        </View>
        <View className={$style.body}>
            {props.children}
        </View>
    </View>
}